/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.brands.application.ics.dao;

import br.com.brands.application.ics.beans.ProductsBeans;
import java.io.Serializable;
import java.util.List;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

/**
 *
 * @author ppacheco
 */
public class ProductsDAOImpl<T, ID extends Serializable> extends GenericDAOImpl<Object, Serializable> {

    /**
     *
     */
    private static final long serialVersionUID = -7112278458841768317L;
    private Logger log = Logger.getLogger(ProductsDAOImpl.class.getName());

    public ProductsDAOImpl() {
        log.log(Level.INFO, "Loading ProductsDAOImpl");
    }

    /**
     *
     * @param products
     * @return
     * @throws HibernateException
     * @throws InstantiationException
     */
    @SuppressWarnings("unchecked")
    public Serializable save(ProductsBeans products) throws HibernateException,
            InstantiationException {

        ID id = null;

        try {
            id = (ID) super.save(products);
        } catch (Exception e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return id;
    }

    /**
     *
     * @param products
     * @throws HibernateException
     * @throws InstantiationException
     */
    public void saveOrUpdate(ProductsBeans products) throws HibernateException,
            InstantiationException {

        try {
            super.saveOrUpdate(products);
        } catch (Exception e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
    }

    /**
     *
     * @param products
     * @throws HibernateException
     * @throws InstantiationException
     */
    public void delete(ProductsBeans products) throws HibernateException,
            InstantiationException {
        try {
            super.delete(products);
        } catch (Exception e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
    }

    /**
     *
     * @param products
     * @param id
     * @param lock
     * @return
     * @throws HibernateException
     * @throws InstantiationException
     */
    public Object findByID(ProductsBeans products, Serializable id, boolean lock)
            throws HibernateException, InstantiationException {

        Object o = null;

        try {
            o = (Object) super.findByID(products, id, lock);
        } catch (Exception e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return o;
    }

    /**
     *
     * @param products
     * @return
     * @throws HibernateException
     * @throws InstantiationException
     */
    public List<Object> findAll(ProductsBeans products)
            throws HibernateException, InstantiationException {

        List<Object> list = null;

        try {
            list = (List<Object>) super.findAll(products);
        } catch (Exception e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return list;
    }
}
